home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char rcsid[] = "$Header: xpieces.c,v 1.9 87/05/19 18:46:27 schoch Exp $";
- #endif
-
- #include "externs.h"
-
- #define piece_width 64
- #define piece_height 64
- #include "pawn.h"
- #include "pawn_mask.h"
- #include "bishop.h"
- #include "bishop_mask.h"
- #include "queen.h"
- #include "queen_mask.h"
- #include "king.h"
- #include "king_mask.h"
- #include "rook.h"
- #include "rook_mask.h"
- #include "knight.h"
- #include "knight_mask.h"
- #include "icon.h"
-
- Pixmap icon_pixmap;
-
- p_init()
- {
- Pixmap mask, piece;
- Bitmap bp;
-
- bp = XStoreBitmap(piece_width, piece_height, pawn_bits);
- piece = XMakePixmap(bp, WhitePixel, BlackPixel);
- XFreeBitmap(bp);
- pieces_icons[PAWN] = piece;
-
- bp = XStoreBitmap(piece_width, piece_height, pawn_mask_bits);
- mask = XMakePixmap(bp, WhitePixel, BlackPixel);
- XFreeBitmap(bp);
- pieces_masks[PAWN] = mask;
-
-
- bp = XStoreBitmap(piece_width, piece_height, bishop_bits);
- piece = XMakePixmap(bp, WhitePixel, BlackPixel);
- XFreeBitmap(bp);
- pieces_icons[BISHOP] = piece;
-
- bp = XStoreBitmap(piece_width, piece_height, bishop_mask_bits);
- mask = XMakePixmap(bp, WhitePixel, BlackPixel);
- XFreeBitmap(bp);
- pieces_masks[BISHOP] = mask;
-
-
- bp = XStoreBitmap(piece_width, piece_height, queen_bits);
- piece = XMakePixmap(bp, WhitePixel, BlackPixel);
- XFreeBitmap(bp);
- pieces_icons[QUEEN] = piece;
-
- bp = XStoreBitmap(piece_width, piece_height, queen_mask_bits);
- mask = XMakePixmap(bp, WhitePixel, BlackPixel);
- XFreeBitmap(bp);
- pieces_masks[QUEEN] = mask;
-
-
- bp = XStoreBitmap(piece_width, piece_height, king_bits);
- piece = XMakePixmap(bp, WhitePixel, BlackPixel);
- XFreeBitmap(bp);
- pieces_icons[KING] = piece;
-
- bp = XStoreBitmap(piece_width, piece_height, king_mask_bits);
- mask = XMakePixmap(bp, WhitePixel, BlackPixel);
- XFreeBitmap(bp);
- pieces_masks[KING] = mask;
-
-
- bp = XStoreBitmap(piece_width, piece_height, rook_bits);
- piece = XMakePixmap(bp, WhitePixel, BlackPixel);
- XFreeBitmap(bp);
- pieces_icons[ROOK] = piece;
-
- bp = XStoreBitmap(piece_width, piece_height, rook_mask_bits);
- mask = XMakePixmap(bp, WhitePixel, BlackPixel);
- XFreeBitmap(bp);
- pieces_masks[ROOK] = mask;
-
-
- bp = XStoreBitmap(piece_width, piece_height, knight_bits);
- piece = XMakePixmap(bp, WhitePixel, BlackPixel);
- XFreeBitmap(bp);
- pieces_icons[KNIGHT] = piece;
-
- bp = XStoreBitmap(piece_width, piece_height, knight_mask_bits);
- mask = XMakePixmap(bp, WhitePixel, BlackPixel);
- XFreeBitmap(bp);
- pieces_masks[KNIGHT] = mask;
-
- bp = XStoreBitmap(icon_width, icon_height, icon_bits);
- icon_pixmap = XMakePixmap(bp, WhitePixel, BlackPixel);
- XFreeBitmap(bp);
-
- iconwindow = XCreateWindow(RootWindow, 0, 0,
- icon_width, icon_height, 0, 0, 0);
-
- XSetIconWindow(window, iconwindow);
- XSelectInput(iconwindow, ExposeWindow);
- }
-
- redraw_pieces()
- {
- int row, col, spot;
-
- for (row = 1; row <= 8; row++)
- for (col = 1; col <= 8; col++) {
- spot = 10 * row + col;
- if (ghost[spot] && state == PLAYING)
- redraw_ghost(spot);
- else if (whose[spot] == ourcolor ||
- (state != PLAYING && occupant[spot]))
- redraw_piece(spot);
- }
- XPixSet(window, 0, 18, 64*8, 64, BlackPixel);
- XPixSet(window, 0, TOPSPACE+64*8, 64*8, 64, BlackPixel);
- for (spot = 0; spot < 32; spot+=2)
- if (captured[spot])
- redraw_captured(spot);
- for (spot = 1; spot < 32; spot+=2)
- if (captured[spot])
- redraw_captured(spot);
- }
-
- redraw_ghost(spot)
- {
- Pixmap mask, icon;
- register x, y;
-
- if (reverse) {
- x = (8-spot%10) * 64;
- y = (8-spot/10) * 64 + TOPSPACE;
- } else {
- x = (spot%10-1) * 64;
- y = (spot/10-1) * 64 + TOPSPACE;
- }
- if (ghost[spot] == 0) {
- fprintf("no ghost at %d\n", spot);
- return;
- }
- mask = pieces_masks[ghost[spot]];
- icon = pieces_icons[ghost[spot]];
-
- if (mask == 0) {
- fprintf(stderr, "Invalid mask for location %d, occupied by %d\n",
- spot, ghost[spot]);
- return;
- }
- if (icon == 0) {
- fprintf(stderr, "Invalid icon for location %d, occupied by %d\n",
- spot, ghost[spot]);
- return;
- }
- XPixmapPut(window, 0, 0, x, y, 64, 64,
- icon, (theircolor==WHITE) ? GXor : GXandInverted, 1);
- }
-
- redraw_piece(spot)
- {
- Pixmap mask, icon;
- register x, y;
-
- if (reverse) {
- x = (8-spot%10) * 64;
- y = (8-spot/10) * 64 + TOPSPACE;
- } else {
- x = (spot%10-1) * 64;
- y = (spot/10-1) * 64 + TOPSPACE;
- }
- if (whose[spot] != ourcolor && state == PLAYING) {
- fprintf(stderr, "cannot draw spot %d: occupied by %d\n",
- spot, occupant[spot]);
- return;
- }
- mask = pieces_masks[occupant[spot]];
- icon = pieces_icons[occupant[spot]];
-
- if (mask == 0) {
- fprintf(stderr, "Invalid mask for location %d, occupied by %d\n",
- spot, occupant[spot]);
- return;
- }
- if (icon == 0) {
- fprintf(stderr, "Invalid icon for location %d, occupied by %d\n",
- spot, occupant[spot]);
- return;
- }
- if (ghost[spot])
- redraw_pos(spot);
- XPixmapPut(window, 0, 0, x, y, 64, 64,
- mask, (whose[spot]==WHITE) ? GXor : GXandInverted, 1);
- XPixmapPut(window, 0, 0, x, y,
- 64, 64, icon, (whose[spot]==WHITE) ? GXandInverted :
- GXor, 1);
- }
-
- redraw_captured(n)
- {
- int piece = captured[n];
- int color;
- int x, y;
- Pixmap mask, icon;
-
- if (n < 16) {
- y = 18;
- color = WHITE;
- } else {
- n -= 16;
- y = 64+18 + 8*64;
- color = BLACK;
- }
- if (reverse) {
- if (color == WHITE)
- y = 64+18 + 8*64;
- else
- y = 18;
- }
- x = n*32;
- mask = pieces_masks[piece];
- icon = pieces_icons[piece];
- if (mask == 0 || icon == 0)
- return;
- if (color == ourcolor || state != PLAYING) {
- XPixmapPut(window, 0, 0, x, y, 64, 64,
- mask, (color==WHITE) ? GXor : GXandInverted, 1);
- XPixmapPut(window, 0, 0, x, y,
- 64, 64, icon, (color==WHITE) ? GXandInverted :
- GXor, 1);
- } else
- XPixmapPut(window, 0, 0, x, y, 64, 64, icon, GXor, 1);
- }
-
- redraw_icon(reverse)
- bool reverse;
- {
- XPixmapPut(iconwindow, 0, 0, 0, 0, icon_width, icon_height,
- icon_pixmap, reverse ? GXcopyInverted : GXcopy, 1);
- }
-